/*===============================================
Copyright (c): Technology Co.,Ltd. ALL rights reserved. 
                                                                 
  Create by: Lin
      Email:
       Date:
   Filename:
Description:
    Version:
Last Change:
                                                                 
=======================================*/
                                                                 
`ifndef MII_MONITOR_SV
`define MII_MONITOR_SV

`include "mii_seq_item.sv"

class mii_monitor extends uvm_monitor;
	`uvm_component_utils(mii_monitor)
	virtual interface mii_if vif;
	uvm_analysis_port #(mii_seq_item) analysis_port;
	
	mii_seq_item m_trans;

	extern function new(string name, uvm_component parent);
	extern virtual function void build_phase(uvm_phase phase);
	extern virtual function void connect_phase(uvm_phase phase);
	extern task main_phase(uvm_phase phase);
	extern task do_mon(mii_seq_item trans);

endclass

function mii_monitor::new(string name, uvm_component parent);
	super.new(name, parent);
	analysis_port = new("analysis_port", this);
endfunction

function void mii_monitor::build_phase(uvm_phase phase);
	super.build_phase(phase);
endfunction

function void mii_monitor::connect_phase(uvm_phase phase);
	super.connect_phase(phase);
	if (!uvm_config_db #(virtual mii_if)::get(this, "", "vif", vif))
			`uvm_error("NOVIF", {"virtual interface must be set for: ", get_full_name, "vif"})
endfunction

task mii_monitor::main_phase(uvm_phase phase);
	`uvm_info(get_type_name(), "main_phase", UVM_HIGH)
	@(vif.mon_clk);
	forever begin
		m_trans = mii_seq_item::type_id::create("m_trans");
		do_mon(m_trans);
		`uvm_info(get_type_name(), "receive trans", UVM_LOW)
		m_trans.print();
		analysis_port.write(m_trans);
	end
endtask

task mii_monitor::do_mon(mii_seq_item trans);
	trans.mii_rx_data <= vif.mon_clk.mii_rx_data;
	trans.mii_rx_dv <= vif.mon_clk.mii_rx_dv;
	trans.mii_tx_data <= vif.mon_clk.mii_tx_data;
	trans.mii_tx_en <= vif.mon_clk.mii_tx_en;
	@(vif.mon_clk);
endtask

`endif
